//package com.cdinternationalcompany.syhapp.common.channel
//
//import android.text.TextUtils
//import android.util.Log
//import com.cdinternationalcompany.syhapp.utils.OnFlutterCall
//import com.cdinternationalcompany.syhapp.utils.OnFlutterCall.Companion.CHANNEL_RESULT_OK
//import com.google.gson.Gson
//import com.google.gson.reflect.TypeToken
//import io.flutter.plugin.common.MethodChannel
//import org.json.JSONObject
//
//abstract class BaseApi<T, R> : OnFlutterCall {
//
//    companion object {
//        const val TAG = "Channel.BaseApi"
//    }
//
//    override fun call(arguments: String, result: MethodChannel.Result): Any {
//        var param: T
//        if (TextUtils.isEmpty(arguments)) {
//            param = arguments as T
//        } else {
//            try {
//                param = Gson().fromJson<T>(arguments, object : TypeToken<T>() {}.type)
//                Log.d(TAG, "Convert data success, doAction by subclass.")
//            } catch (e: Exception) {
//                param = arguments as T
//            }
//        }
//        doAction(param, result)
//        return CHANNEL_RESULT_OK
//    }
//
//    abstract fun doAction(param: T, result: MethodChannel.Result)
//
//    protected fun success(result: MethodChannel.Result, content: JSONObject) {
//        val map: Map<String, Any> = Gson().fromJson(content.toString(), object : TypeToken<Map<String, Any>>() {}.type)
//        success(result, map)
//    }
//
//    protected fun success(result: MethodChannel.Result, content: Any) {
//        result.success(content)
//    }
//
//    protected fun error(result: MethodChannel.Result, cause: String) {
//        result.success(mutableMapOf<String, Any>().apply {
//            put("status", false)
//            put("content", cause)
//        })
//    }
//}